﻿using System;
using System.ComponentModel;
using System.Linq;
using System.Text.RegularExpressions;

namespace Utils.Weixin.Models
{
    public class IdCardInfo
    {

        [DisplayName("姓名")]
        public string name { get; set; }

        [DisplayName("身份证号")]
        public string id { get; set; }

        public string type { get; set; }

        [DisplayName("性别")]
        public string gender { get; set; }


        [DisplayName("地址")]
        public string addr { get; set; }

        [DisplayName("有效期")]
        public string valid_date { get; set; }

        [DisplayName("有效期开始")]
        public DateTime? valid_date_start => ToDate(valid_date?.Split('-')?.FirstOrDefault());

        [DisplayName("有效期结束")]
        public DateTime? valid_date_end => ToDate(valid_date?.Split('-')?.LastOrDefault());


        private DateTime? ToDate(string str)
        {
            if (str.IsNullOrEmpty())
            {
                return null;
            }
            str = Regex.Replace(str, "[.]", "");
            if (!int.TryParse(str, out int v))
            {
                return null;
            }
            return v.ToDate();
        }
    }
}
